昨天新加了” Check-in “ 的功能,今天來做一個”取消check-in” 的 功能
我們可以概略的了解整個流程 :
var restaurantIsVisited = Array(repeating:false,count:(21))
tableView(_tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath), cellForRowAt indexPath: IndexPath)
true -> checkmarkfalse -> none
//Reflash and update the checkmark
            if restaurantIsVisited[indexPath.row] {
                cell.accessoryType = .checkmark
            } else {
                cell.accessoryType = .none
            }
tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)  中將” Check-in “的 選單以及動作加入 menurestaurantIsVisited 改變對應的布林函數。// add check-in cell
            let checkInAction = UIAlertAction(title:"Check in", style: .default , handler:
            {
                (action:UIAlertAction!) -> Void in              
                let cell = tableView.cellForRow(at: indexPath)
                cell?.accessoryType = .checkmark                
                self.restaurantIsVisited[indexPath.row] = true
            })
            optionMenu.addAction(checkInAction)
了解整個流程後可以發現,前置作業都已經差不多,就差把 cancelCheckIn 加入 menu 選單
// add check-in cancel cell
            let cancelCheckInAction = UIAlertAction(title:"Cancel Check in", style: .default , handler:
            {
                (action:UIAlertAction!) -> Void in
                
                let cell = tableView.cellForRow(at: indexPath)
                cell?.accessoryType = .none
                
                self.restaurantIsVisited[indexPath.row] = false
                
            })
            optionMenu.addAction(cancelCheckInAction)
這樣就可以了
